how to define a nested function in python